package com.dgh.school.controller;

import com.dgh.school.bean.Paper;
import com.dgh.school.common.R;
import com.dgh.school.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PaperController {

    @Autowired
    private PaperService paperService;

    @RequestMapping("/file/files")
    public R selectByPage(int pageNum, int pageSize){
        try {
            return paperService.selectByPage(pageNum,pageSize);
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/file/delete")
    public R deleteById(int id){
        try {
            paperService.deleteById(id);
            System.out.println(id);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/file/add")
    public R add(Paper paper){
        try {
            paperService.insertData(paper);
            System.out.println(paper);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/file/modify")
    public R modify(Paper paper){
        try {
            paperService.updateData(paper);
            System.out.println(paper);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

//    @RequestMapping("/file/fileall")
//    public R selectAllDutys(){
//        try {
//
//            return paperService.selectAllFiles();
//        } catch (Exception e) {
//            return R.error();
//        }
//    }

}
